package com.hang.ixin.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.springframework.stereotype.Component;

@Component
public class NettyServer {

    private ServerBootstrap bootstrap;
    private ChannelFuture future;
    private static class SingletonNettyServer {
        private static NettyServer server = new NettyServer();
    }
    public static NettyServer getInstance(){
        return SingletonNettyServer.server;
    }
    private NettyServer(){
        EventLoopGroup boss = new NioEventLoopGroup();
        EventLoopGroup worker = new NioEventLoopGroup();
        bootstrap = new ServerBootstrap();
        bootstrap.group(boss,worker).channel(NioServerSocketChannel.class).childHandler(new WSInitializer());
    }
    public void start(){
        this.future = bootstrap.bind(8088);
    }
}
